package day02;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

//@WebServlet("/testRequest")
//@WebServlet("/test/request")
//@WebServlet("/test/*")
@WebServlet("*.test")
public class TestRequestServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //应用名
        System.out.println("request.getContextPath() = " + request.getContextPath());

        //url-pattern
        System.out.println("request.getServletPath() = " + request.getServletPath());

        //地址栏
        System.out.println("request.getRequestURL() = " + request.getRequestURL());

        //contextPath+servletPath
        System.out.println("request.getRequestURI() = " + request.getRequestURI());



        //告诉容器，解析请求体中的数据使用utf-8编码
        request.setCharacterEncoding("utf-8");




        //获得请求方法
        System.out.println("request.getMethod() = " + request.getMethod());
        
        //获得客户端ip地址
        System.out.println("request.getRemoteAddr() = " + request.getRemoteAddr());
        
        //获得请求头中的数据
        System.out.println("request.getHeader(\"User-Agent\") = " + request.getHeader("User-Agent"));

        //获得请求参数
        request.getParameter("");
        request.getParameterValues("");

        Map<String,String[]> map=request.getParameterMap();

        map.forEach((k,v)-> System.out.println(k+"="+ Arrays.toString(v)));


    }
}
